#include <iostream>
using namespace std;

class Vehicle {
private:
    string owner;
    string license;

public:
    Vehicle() = default;

    virtual void GetInfo() {
        cout << "请输入车主姓名: ";
        cin >> owner;

        cout << "请输入车牌号, 如NM 123 ABC: ";
        cin >> license;
    }

    virtual void WriteInfo() {
        cout << "车主: " << owner << ", 车牌号: " << license << "\n";
    }
};

class RV : public Vehicle {
private:
    int category; // RV大小分为1, 2, 3

public:
    RV() = default;

    void GetInfo() override {
        cout << "请输入休闲车的信息:\n";
        Vehicle::GetInfo();

        cout << "输入休闲车的类型1、2或3: ";
        cin >> category;

        char enter;
        cin.get(enter); // 非常重要
    }

    void WriteInfo() override {
        Vehicle::WriteInfo();
        cout << "这辆休闲车的类型为: " << category << "\n";
    }
};

class Semi : public Vehicle {
private:
    double weight_cap;

public:
    Semi() = default;

    void GetInfo() override {
        cout << "请输入商用车的信息:\n";
        Vehicle::GetInfo();

        cout << "输入载重: ";
        cin >> weight_cap;

        char enter;
        cin.get(enter);
    }

    void WriteInfo() override {
        Vehicle::WriteInfo();
        cout << "这辆商用车的载重为: " << weight_cap << "\n";
    }
};

int main() {
    cout << "两辆车和虚函数\n";

    RV haveFun;
    Semi goToWork;

    Vehicle* base[2] {
        &haveFun,
        &goToWork
    };

    for (int i = 0; i < 2; i++) {
        base[i]->GetInfo();
    }

    for (int i = 0; i < 2; i++) {
        base[i]->WriteInfo();
    }

    cout << "我们去郊游吧。\n";
}
